package Simple2;

import java.math.BigInteger;

public class Factorial_sum {

	
	public int solution(int N){
		if(N<1 || N>2000)
			return -1;		
		BigInteger temp=new BigInteger("1");	
		int to_return = 0;
		for(int i=2;i<N+1;i++){
			temp=temp.multiply(new BigInteger(Integer.toString(i)));
		}	
		char[] temp3 = temp.toString().toCharArray();
		for(int i=0;i<temp3.length;i++){
			if(to_return>100000000)
				return -1;
			to_return+=Integer.parseInt(String.valueOf(temp3[i]));
		}
		return to_return;		
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Factorial_sum test = new Factorial_sum();
		System.out.println(test.solution(2000));
	}
}
